package org.cms.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ConfigurableApplicationContext;
import java.net.InetAddress;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RunConfig implements CommandLineRunner {

    private final ConfigurableApplicationContext context;

    public RunConfig(ConfigurableApplicationContext context) {
        this.context = context;
    }

    @Override
    public void run(String... args) {
        String host = InetAddress.getLoopbackAddress().getHostAddress();
        String port = context.getEnvironment().getProperty("server.port");
        String contextPath = context.getEnvironment().getProperty("server.servlet.context-path", "");
        System.out.printf("API: https://%s:%s%sapi%n", host, port, contextPath);
    }

}
